package com.gable.exhibition.init;

import com.alibaba.fastjson.JSON;
import com.gable.exhibition.dao.ManufacturerMaintainerDao;
import com.gable.exhibition.view.ManufacturerMaintainerView;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by mj on 2018/3/16.
 */
@Component
public class MaintainerManufacturerInit {
    Logger logger = Logger.getLogger(this.getClass());

    @Autowired
    ManufacturerMaintainerDao manufacturerMaintainerDao;


    public static Map<Long,ManufacturerMaintainerView> maintainerManufacturerMap = null;


    public void queryMaintainerManufacturer(){
        logger.debug("维修商和厂商之间的关系初始化开始");
        if(maintainerManufacturerMap == null){
            maintainerManufacturerMap = new HashMap<Long,ManufacturerMaintainerView>();
        }

        List<ManufacturerMaintainerView> list =  manufacturerMaintainerDao.maintainerManufacturerInit();
        for(ManufacturerMaintainerView mm : list){
            Long maintainerId = mm.getMaintainerId();
            maintainerManufacturerMap.put(maintainerId,mm);
        }
        logger.debug("维修商和厂商之间的关系初始化结束");
        logger.debug("结果集："+ JSON.toJSONString(maintainerManufacturerMap));
    }
}
